﻿//定义地图全局变量，默认显示城市
//var map_city = "龙岩";
var siteUrl=""; //站点的地址 域名或ip
//支付支付地址，联通的支付需要,根据站点获取
//var alipayhurl="http://47.56.90.51:18080/unicom/alipay";
var alipayhurl="http://localhost:18080/unicom/alipay";
//json 日期格式转换 y-m-d
function jsonDateFormat(jsonDate) {//json日期格式转换为正常格式
    try {
        var date = new Date(parseInt(jsonDate.replace("/Date(", "").replace(")/", ""), 10));
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        var hours = date.getHours();
        var minutes = date.getMinutes();
        var seconds = date.getSeconds();
        var milliseconds = date.getMilliseconds();
        return date.getFullYear() + "-" + month + "-" + day;
    } catch (ex) {
        return "";
    }
}

//json 日期格式转换 y-m-d h:m:s
function jsonDateTimeFormat(jsonDate) {//json日期格式转换为正常格式
    try {
        var date = new Date(parseInt(jsonDate.replace("/Date(", "").replace(")/", ""), 10));
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
        var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
        var seconds = date.getSeconds();
        var milliseconds = date.getMilliseconds();
        return date.getFullYear() + "-" + month + "-" + day + " " + hours + ":" + minutes;
    } catch (ex) {
        return "";
    } 

}

function isNull(value,replaceValue) {  
    if (value == "" || value == null || value== "undefined")
        return replaceValue;
    else
        return value;
}
//百分比计算
function percentage(value,total) {
    var result=0;
    if (value != "" && total != null && total!=0)
    {
        result=value/total;
    }
        return result;

}
//绑定下拉商户--通道****************************
function bindClientAisleselect() {

    $.ajax({
        url: "/aisle/getUserAisle",
        type: "get",
        contentType: "application/json",
        dataType: "json",
        success: function (data) {
            var ddl1 = $("#select_ClientAisle");
            //删除节点
            $("#select_ClientAisle optgroup").remove();
            $("#select_ClientAisle option").remove();
            //转成Json对象
            // var result = eval(data.data);
            var result = eval(data);
            var opt1 = $("<option value=''></option>").text("--请选择--").val("");

            ddl1.append(opt1);

            //循环遍历 下拉框绑定
            $(result).each(function (index,value) {
                //添加option 对应Json对象名称
                opt1 = $("<optgroup label='"+value.userName+"'></optgroup>");
                ddl1.append(opt1);
                $(value.aisle).each(function (index2,value2) {
                    opt1 = $("<option></option>").text(" ├"+value2.name).val(value2.id);
                    ddl1.append(opt1);
                });

            });
        },
        error: function () {
            // alert("Error");
        }
    });

}
//订单状态****************************
function orderState(state) {
    var optionHtml = "";
    if (state == -1) {
        optionHtml = "超时关闭";
    }
    else if (state == 0) {
        optionHtml = "待处理";
    }
    else if (state == 1) {
        optionHtml = "提起数据";
    }
    else if (state == 3) {
        optionHtml = "已抓起支付地址";
    }
    else if (state == 4) {
        optionHtml = "已收支付地址";
    }
    else if (state == 5) {
        optionHtml = "支付完成";
    }
    else if (state == 6) {
        optionHtml = "已收到通知";
    }
    else if (state == 10) {
        optionHtml = "提现待审核";
    }
    else if (state == 11) {
        optionHtml = "提现待确认";
    }
    else if (state == 12) {
        optionHtml = "已提现";
    }
    else if (state == -3) {
        optionHtml = "抓支付地址失败";
    }
    else if (state == -4) {
        optionHtml = "匹配失败";
    }
    else {
        optionHtml = "未知状态";
    }
    return optionHtml;
}
//获取url地址的参数****************************
function getQueryVariable(variable)
{
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
        if(pair[0] == variable){return pair[1];}
    }
    return(0);
}